package aptean外资公司笔试;
//题2
public class PowAndSort {
    public static void main(String[] args) {
        int [] a = new int[]{-7,-3,2,3,11};
        fun(a);
        for (int j : a) {
            System.out.println(j);
        }
    }

    public static void fun(int[] a){
        int p = 0;
        while (p<a.length && a[p] < 0){
            p++;
        }
        p--;//指向最后一个负数
        for (int i = 0; i <=p; i++) {//调正
            a[i] = a[i]>0?a[i]:-a[i];
        }
        sort(a);
        for (int i=0;i<a.length;i++){
            a[i] = a[i]*a[i];
        }
    }


    public static void sort(int[]a){
        for (int i = 1; i < a.length; i++) {
            for (int j = 0;j<a.length-i;j++){
                if (a[j]>a[j+1]){
                    int temp = a[j];
                    a[j] = a[j+1];
                    a[j+1]=temp;
                }
            }
        }
    }
}
